home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.05 May 90 / PrintWindow Code / PrintWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-02  |  4.3 KB  |  172 lines  |  [TEXT/KAHL]

  1. /********************************
  2. Program name:  PrintWindow.c
  3. *********************************/
  4. /**********************
  5. Include files
  6. ***********************/
  7. #include "String.h"
  8. #include "MyWindow.h"
  9. #include "Messenger.h"
  10.  
  11. /**********************
  12. main() main entry point
  13. ***********************/
  14. void main()
  15. { /* main() */
  16. char    doneFlag;
  17. char    stillInGoAway;
  18. char    ch;
  19. short    code;
  20. short    theMenu,theItem;
  21. short    chCode;
  22. long    mResult;
  23. WindowPtr    whichWindow;
  24. EventRecord    myEvent;
  25. TEHandle    theInput;
  26. Rect    tempRect,OldRect;
  27. Point    myPt;
  28. GrafPtr    SavePort; 
  29.  
  30. /* Initialize everything */
  31. InitGraf(&thePort);
  32. InitFonts();
  33. FlushEvents(everyEvent,0);
  34. InitWindows();
  35. InitMenus();
  36. TEInit();
  37. InitDialogs(NULL);
  38. InitCursor();
  39.  
  40. InitPrint();
  41. InitMyMenus();
  42. InitMessage();
  43. Init_MyWindow();
  44.  
  45. doneFlag = FALSE;
  46. theInput = NULL;
  47.  
  48. /* open the MyWindow */
  49. Open_MyWindow(&theInput);
  50.      
  51. do { /* main event loop */
  52.     if (theInput != NULL)
  53.         TEIdle(theInput);
  54.     SystemTask();
  55.  
  56.     if (GetNextEvent(everyEvent, &myEvent)) { /* get an event */
  57.         code = FindWindow(myEvent.where, &whichWindow);
  58.  
  59.         switch (myEvent.what) { /* handle an event */
  60.             case mouseDown:
  61.                 if (code == inMenuBar) {
  62.                     mResult = MenuSelect(myEvent.where);
  63.                     theMenu = HiWord(mResult);
  64.                     theItem = LoWord(mResult);
  65.                     HandleMenu(&doneFlag,theMenu,theItem);
  66.                     }
  67.  
  68.                  if ((code == inDrag)&&(whichWindow != NULL)) {
  69.                      tempRect = screenBits.bounds;
  70.                      SetRect(&tempRect, 
  71.                              tempRect.left + 10, tempRect.top + 25, 
  72.                              tempRect.right - 10, tempRect.bottom - 10);
  73.                      DragWindow(whichWindow, myEvent.where, &tempRect);
  74.                     }
  75.  
  76.                 if (code == inGrow) {
  77.                     SetPort(whichWindow);
  78.  
  79.                     myPt = myEvent.where;
  80.                     GlobalToLocal(&myPt);
  81.                      OldRect = whichWindow->portRect;
  82.                     
  83.                     SetRect(&tempRect,15,15,
  84.                             (screenBits.bounds.right - screenBits.bounds.left), 
  85.                             (screenBits.bounds.bottom - screenBits.bounds.top) - 20);
  86.                     mResult = GrowWindow(whichWindow, myEvent.where, &tempRect);
  87.                     SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
  88.  
  89.                     Resized_MyWindow(&OldRect, whichWindow);
  90.  
  91.                     SetPort(whichWindow);
  92.  
  93.                     SetRect(&tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15);
  94.                     EraseRect(&tempRect);
  95.                     InvalRect(&tempRect);
  96.                     SetRect(&tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);
  97.                     EraseRect(&tempRect);
  98.                     InvalRect(&tempRect);
  99.                     DrawGrowIcon(whichWindow);
  100.                     }
  101.  
  102.                 if (code == inGoAway) {
  103.                     stillInGoAway = TrackGoAway(whichWindow,myEvent.where);
  104.                     if (stillInGoAway == TRUE)
  105.                         Close_MyWindow(whichWindow,&theInput);
  106.                     }
  107.  
  108.                 if (code == inContent) {
  109.                     if (whichWindow != FrontWindow())
  110.                         SelectWindow(whichWindow);
  111.                     else {
  112.                         SetPort(whichWindow);
  113.                         Do_MyWindow (&myEvent,&theInput );
  114.                         }
  115.                     }
  116.  
  117.                 if (code == inSysWindow)
  118.                     SystemClick(&myEvent, whichWindow);
  119.                 break; /* End of mouseDown */
  120.  
  121.             case keyDown:
  122.             case autoKey:
  123.                 ch = myEvent.message &  charCodeMask;
  124.                 if (myEvent.modifiers & cmdKey) {
  125.                     mResult = MenuKey(ch);
  126.                     theMenu = HiWord(mResult);
  127.                     theItem = LoWord(mResult);
  128.                     if (theMenu != 0)
  129.                         HandleMenu(&doneFlag, theMenu, theItem);
  130.                     if (((ch == 'x') || (ch == 'X')) && (theInput != NULL))
  131.                         TECut(theInput);
  132.                     if (((ch == 'c') || (ch == 'C')) && (theInput != NULL))
  133.                         TECopy(theInput);
  134.                     if (((ch == 'v') || (ch == 'V')) && (theInput != NULL))
  135.                         TEPaste(theInput);
  136.                     }
  137.                 else if (theInput != NULL)
  138.                     TEKey(ch,theInput);
  139.                 break;
  140.  
  141.             case updateEvt:
  142.                 whichWindow = (WindowPtr)myEvent.message;
  143.                 GetPort(&SavePort);
  144.                 BeginUpdate(whichWindow);
  145.                 SetPort(whichWindow);
  146.                     UpDate_MyWindow(whichWindow);
  147.                 EndUpdate(whichWindow);
  148.                 SetPort(SavePort);
  149.                 break;
  150.  
  151.             case diskEvt:
  152.                 if (HiWord(myEvent.message) != 0) {
  153.                     myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
  154.                     myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
  155.                     InitCursor();
  156.                     theItem = DIBadMount(myEvent.where, myEvent.message);
  157.                     }
  158.                 break;
  159.  
  160.             case activateEvt:
  161.                 if ((whichWindow != NULL) && (myEvent.modifiers & activeFlag)) {
  162.                     SelectWindow(whichWindow);
  163.                     DrawGrowIcon(whichWindow);/* Update this window */
  164.                     }
  165.                 break;
  166.  
  167.             default:
  168.                 break;
  169.              } /* handle an event */
  170.         } /* get an event */
  171.     } while (doneFlag ==  FALSE); /* main event loop */
  172. } /* main() */